package com.knowif.backend.controller;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/fjl")
    public String fjl(){
        //声明返回结果
        String result = "";
        //开始请求API接口时间
        long startTime=System.currentTimeMillis();
        //请求API接口的响应时间
        long endTime= 0L;
        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
            // 创建连接
            HttpGet httpGet = new HttpGet("http://218.17.179.170:9090/K3Cloud/ERPGW.asmx/ValidateSystem?userName=CRM_test&pwd=CRM@2017");
            // 设置报文和通讯格式
//            StringEntity stringEntity = new StringEntity("","utf-8");
//            stringEntity.setContentEncoding("utf-8");
//            httpPost.setEntity(stringEntity);
            //执行发送，获取相应结果
            HttpEntity entity = httpClient.execute(httpGet).getEntity();
            result = EntityUtils.toString(entity);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
